﻿

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

namespace SJM.Core
{
    public record Result<T> : Result
    {
        public T? Data { get; set; }

        public Result()
        {
        }

        public Result(T data)
            : base(isOK: true)
        {
            Data = data;
        }

        public Result(T data, string msg, bool isOK)
            : base(msg, isOK)
        {
            Data = data;
        }

        public Result(string msg, bool isOK = false)
            : base(msg, isOK)
        {
            Data = default(T);
        }

        [CompilerGenerated]
        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("Result");
            stringBuilder.Append(" { ");
            if (PrintMembers(stringBuilder))
            {
                stringBuilder.Append(' ');
            }

            stringBuilder.Append('}');
            return stringBuilder.ToString();
        }

        [CompilerGenerated]
        protected override bool PrintMembers(StringBuilder builder)
        {
            if (base.PrintMembers(builder))
            {
                builder.Append(", ");
            }

            builder.Append("Data = ");
            builder.Append(Data);
            return true;
        }

        [CompilerGenerated]
        public override int GetHashCode()
        {
            return base.GetHashCode() * -1521134295 + EqualityComparer<T>.Default.GetHashCode(Data);
        }

        [CompilerGenerated]
        public virtual bool Equals(Result<T>? other)
        {
            return (object)this == other || (base.Equals(other) && EqualityComparer<T>.Default.Equals(Data, other!.Data));
        }

        [CompilerGenerated]
        protected Result(Result<T> original)
            : base(original)
        {
            Data = original.Data;
        }
    }
    public record Result
    {
        public string? Message { get; set; }

        public int? Code { get; set; }

        public bool IsOK { get; set; }

        public static Result OK = new Result(isOK: true);

        public Result()
        {
            Message = null;
            Code = null;
            IsOK = true;
            
        }

        public Result(bool isOK)
        {
            Message = null;
            Code = null;
            IsOK = true;
            
            IsOK = isOK;
        }

        public Result(string msg)
        {
            Message = null;
            Code = null;
            IsOK = true;
            
            Message = msg;
            IsOK = true;
        }

        public Result(string msg, bool isOK)
        {
            Message = null;
            Code = null;
            IsOK = true;
            
            Message = msg;
            IsOK = isOK;
        }

        public Result(string msg, bool isOK, int? code)
        {
            Message = null;
            Code = null;
            IsOK = true;
            
            Message = msg;
            IsOK = isOK;
            Code = code;
        }

        public static Result Fail(string message)
        {
            return new Result(message, isOK: false);
        }

        [CompilerGenerated]
        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("Result");
            stringBuilder.Append(" { ");
            if (PrintMembers(stringBuilder))
            {
                stringBuilder.Append(' ');
            }

            stringBuilder.Append('}');
            return stringBuilder.ToString();
        }

        [CompilerGenerated]
        protected virtual bool PrintMembers(StringBuilder builder)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();
            builder.Append("Message = ");
            builder.Append((object?)Message);
            builder.Append(", Code = ");
            builder.Append(Code.ToString());
            builder.Append(", IsOK = ");
            builder.Append(IsOK.ToString());
            return true;
        }

        [CompilerGenerated]
        public override int GetHashCode()
        {
            return ((EqualityComparer<Type>.Default.GetHashCode(EqualityContract) * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Message)) * -1521134295 + EqualityComparer<int?>.Default.GetHashCode(Code)) * -1521134295 + EqualityComparer<bool>.Default.GetHashCode(IsOK);
        }

        [CompilerGenerated]
        public virtual bool Equals(Result? other)
        {
            return (object)this == other || ((object)other != null && EqualityContract == other!.EqualityContract && EqualityComparer<string>.Default.Equals(Message, other!.Message) && EqualityComparer<int?>.Default.Equals(Code, other!.Code) && EqualityComparer<bool>.Default.Equals((IsOK ? ((byte)1) : ((byte)0)) != 0, (other!.IsOK ? ((byte)1) : ((byte)0)) != 0));
        }

        [CompilerGenerated]
        protected Result(Result original)
        {
            Message = original.Message;
            Code = original.Code;
            IsOK = original.IsOK;
        }
    }
}
